using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using IGlobalist.Cms.Common;
using IGlobalist.Cms.Bll;
using IGlobalist.Cms.Model;

namespace IGlobalist.Cms
{
    public partial class MovieFeed : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Stream mstream=null;
             int blogID =0;
            try{
                blogID  = Convert.ToInt32(Request["bid"]);
                if  (Request["type"]!=null)
                {
                    string type= Request["type"];
                    string path;
                    if (type=="flvv")
                        path=Server.MapPath("CmsData/Videos/" + blogID +".flv");
                    else
                        path=Server.MapPath("CmsData/Videos/" + blogID +".flv");
                    mstream= new FileStream(path,FileMode.Open,FileAccess.Read);
                }

                //byte buffer;
                int bl=1024;
                int readed=0;
                byte[] buffer= new byte[bl];

                readed= mstream.Read(buffer,0,bl);
                while (readed>0)
                {
                    Response.OutputStream.Write(buffer,0,readed);
                    readed=mstream.Read(buffer,0,bl);
                }
                Response.OutputStream.Flush();
                mstream.Close();

                Video video = VideoController.GetVideo(blogID);
                video.Views = video.Views + 1;
                VideoController.UpdateVideo(video);

            }
            catch
            {
            }
            
        }
    }
}
